package com.baselibrary.test.app;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;

import com.baselibrary.libs.Utils.log.LogUtils;
import com.baselibrary.libs.Utils.netUtils.NoHttp.queueList.QueueNetWork;
import com.baselibrary.test.servers.DemoPushService;
import com.igexin.sdk.PushManager;


/**
 * Created by 35876 于萌萌
 * 创建日期: 13:27 . 2016年11月09日
 * 描述:
 * <p>
 * <p>
 * 备注:
 */

public class AppContext extends Application {
    // 获取到主线程的上下文
    private static AppContext mContext = null;
    // 获取到主线程的handler
    private static Handler mMainThreadHandler = null;

    // 获取到主线程
    private static Thread mMainThread = null;
    // 获取到主线程的id
    private static int mMainThreadId;
    // 获取到主线程的looper
    private static Looper mMainThreadLooper = null;

    private static QueueNetWork mControlQueue = null;
    private static int mSize;

    public static QueueNetWork getmControlQueue() {
        return mControlQueue;
    }

    private static String Url = "http://192.168.0.172:8080/";

    @Override
    public void onCreate() {
        super.onCreate();
        this.mContext = this;
        this.mMainThreadHandler = new Handler();
        this.mMainThread = Thread.currentThread();
        this.mMainThreadId = android.os.Process.myTid();
        this.mMainThreadLooper = getMainLooper();

        mSize = getMemoryCacheSize();
        LogUtils.i("缓存步骤"+"当前可用的内存是"+mSize);
        this.mControlQueue = QueueNetWork.getControlQueue(mContext, 10,mSize);


// com.getui.demo.DemoPushService 为第三方自定义推送服务
       PushManager.getInstance().initialize(this.getApplicationContext(), DemoPushService.class);

        String cid = PushManager.getInstance().getClientid(this);
        LogUtils.i("获取了cid\t"+cid);
        //  MobclickAgent.setDebugMode(true);
        //内存泄漏
       // LeakCanary.install(this);
    }

    /**
     * 获取当前系统可用内存的8/1
     * @return
     */
    public static int getSizeMemoryCacheSize() {
        return mSize;
    }

    /**
     * @description
     *
     *
     * @return 得到需要分配的缓存大小，这里用八分之一的大小来做
     */
    public  int getMemoryCacheSize() {
        // Get memory class of this device, exceeding this amount will throw an
        // OutOfMemory exception.
        final int memClass = ((ActivityManager)getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();

        // Use 1/8th of the available memory for this memory cache.
        return 1024 * 1024 * memClass / 8;
    }

    static String [] ctiyArrays;

    public static void setCtiyArray(String [] ctiyArray){
       ctiyArrays = ctiyArray;
    }
    public static String [] getCtiyArrays(){
        return ctiyArrays;
    }
    static String mSms ;
    public static void setSmsCode(String sms){
         mSms = sms;
    }

    public static String getSmsCode() {
        return mSms;
    }

    // 对外暴露上下文
    public static AppContext getApplication() {
        return mContext;
    }

    // 对外暴露主线程的handler
    public static Handler getMainThreadHandler() {
        return mMainThreadHandler;
    }

    // 对外暴露主线程
    public static Thread getMainThread() {
        return mMainThread;
    }

    // 对外暴露主线程id
    public static int getMainThreadId() {
        return mMainThreadId;
    }

    // 对外暴露主线程的looper
    public static Looper getMainThreadLooper() {
        return mMainThreadLooper;
    }

    public static String getUrl(){
        return Url;
    }


}
